package org.jetnuke.modules.submitnews;

import org.apache.log4j.Logger;

//import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;

public class Preview implements IAction {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(Preview.class);

	String story, story_ext;

	String posttype;

	int category;

	public void setPosttype(String posttype) {
		this.posttype = posttype;
	}

	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {
		if (logger.isDebugEnabled()) {
			logger
					.debug("exec(HttpServletRequest, HttpServletResponse, VelocityContext, IModuleInfo, String, IUserInfo, IAdminInfo) - start"); //$NON-NLS-1$
		}

		String f_story = null;// $story;
		String f_storyext = null;// $f_storyext = $storyext;
		// if (posttype.equals("plaintext")) {
		// f_story = story.replaceAll("\n", "<br/>"); //equivalent of PHP
		// function "nl2br"
		// f_storyext = story_ext.replaceAll("\n", "<br/>");
		// } else {
		f_story = story;
		f_storyext = story_ext;
		// }
		String story2 = f_story + "<br/><br/>" + f_storyext;
		vc.put("story2", story2);
		vc.put("cats", DataAccessDriver.getInst().newTopicsDAO().selectAll());// topicsPeer.doSelect(new
																				// Criteria()));
		vc.put("sel_cat", new Integer(category));
		ActionForward returnActionForward = new ActionForward(op, info);
		if (logger.isDebugEnabled()) {
			logger
					.debug("exec(HttpServletRequest, HttpServletResponse, VelocityContext, IModuleInfo, String, IUserInfo, IAdminInfo) - end"); //$NON-NLS-1$
		}
		return returnActionForward;
	}

	/**
	 * @param story
	 *            The story to set.
	 */
	public void setStory(String story) {
		this.story = story;
	}

	/**
	 * @param story_ext
	 *            The story_ext to set.
	 */
	public void setStory_ext(String story_ext) {
		this.story_ext = story_ext;
	}

	public void setCategory(int category) {
		this.category = category;
	}
}
